// pages/majorProject/majorProject.js
var com=require("../../utils/util.js")
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    select:true,
    currentData:0,
    projectId:'',
    date:'',
    problemState:'',
    informationList:[],
    informationImg:[],
    scheduleList:[],
    problemList:[],
    matterList:[],
    matter_id: 0,
    matter_txt: '请选择',
    deptPhone:'',
    deptPhonePeople:''
  },
  //获取当前index
  bindchange: function (e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function (e) {
    const that = this;
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    } 
    if (that.data.currentData == 1) {
      com.post('project/projectReport/month/speedProject', { proId: this.data.projectId, date: this.data.date}, 'schedule', this)
    }
    if (that.data.currentData == 2) {
      com.post('project/assigned/questionlist', { proId: this.data.projectId, pageSize: app.globalData.pageSize, pageNo: 1 }, 'problemProject', this)
    }
    if (that.data.currentData == 3) {
      com.post('project/projectReport/month/problemProject', { proId: this.data.projectId, problemState:this.data.problemState,pageSize: app.globalData.pageSize, pageNo: 1 }, 'matter', this)
    }
  },
  // 进度情况
  schedule:function(res){
    // console.log(res)
    if (res.code == 200) {

      this.setData({
        scheduleList: res.content
      })
    }
  },
  // 问题情况
  problemProject:function(res){
    // console.log(res)
    if(res.code == 200){
      this.setData({
        problemList: res.content.list
      })
    }
  },
  // 事项情况
  matter: function (res) {
    console.log(res)
    this.setData({
      matterList:res.content.list[0]
    })
    console.log(this.data.matterList)
  },
  filter: function (e) {
    var  id = e.currentTarget.dataset.id, txt = e.currentTarget.dataset.txt
    this.setData({
          matter_id: id,
          matter_txt: txt,
          select: !this.data.select
    })
    com.post('project/projectReport/month/problemProject', { proId: this.data.projectId, problemState: this.data.matter_txt, pageSize: app.globalData.pageSize, pageNo: 1 }, 'matterClose', this)
    }, 
  filterTab:function() {
    this.setData({
      select: !this.data.select
    }) 
  },
  matterClose: function (res) {
    console.log(res)
    this.setData({
      matterList:[],
      matterList: res.content.list[0]
    })
  },
  // 项目单位拨打电话
  dial: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.deptPhone,
    })
  },
  // 项目联系人拨打电话
  dialpeo: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.deptPhonePeople,
    })
  },      
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //获取年月
    var timestamp = Date.parse(new Date());
    var date = new Date(timestamp);
    //获取年份  
    var Y = date.getFullYear();
    //获取月份  
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
      this.setData({
        date:Y + "-" + M
   })
    this.setData({
      projectId: options.id
    }) 
    com.post('project/detail', { projectId: options.id}, 'detail', this)
  },
  detail:function(res){
    // console.log(11)
    // console.log(res)
    if(res.code==200){
      var imageUrl = "http://36.33.216.250:8060/zdxm/file/projectFile/";     
      var url = imageUrl + res.content.liveImg
      res.content.liveImg = url
      this.data.informationImg.push(res.content)    
    }
    this.setData({
      informationList:this.data.informationImg[0],
      problemState: this.data.informationImg[0].proStatus,
      deptPhone: this.data.informationImg[0].deptPhone,
      deptPhonePeople: this.data.informationImg[0].proPhone
    })
    // console.log(this.data.informationList)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})